package com.originskyseed.platform.count.controller;

import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.originskyseed.platform.common.annotation.SysLog;
import com.originskyseed.platform.common.api.util.DataUtil;
import com.originskyseed.platform.core.aspect.annotation.RequiredParams;
import com.originskyseed.platform.core.base.BaseController;
import com.originskyseed.platform.core.base.BaseLocaleResource;
import com.originskyseed.platform.core.base.BasePage;
import com.originskyseed.platform.core.base.BaseResponseBody;
import com.originskyseed.platform.core.common.code.CommonResponseCode;
import com.originskyseed.platform.core.util.bean.ExportExcelUtil;
import com.originskyseed.platform.count.i18n.CountResponseMsg;
import com.originskyseed.platform.count.service.ICountAnchorAndSalesRankListService;
import com.originskyseed.platform.count.vo.CountAnchorAndSalesRankListVO;
import com.originskyseed.platform.count.vo.request.CountAnchorAndSalesRankListRequestVO;

/**
 * Controller类（COUNTANCHORANDSALESRANKLIST）
 *
 * @author wlj
 */
@Controller
@RequestMapping("/ranking")
@BaseLocaleResource(localeFileName = "i18n_count")
public class CountAnchorAndSalesRankListController extends BaseController {

	private static final Logger logger = LoggerFactory.getLogger(CountAnchorAndSalesRankListController.class);

	@DubboReference
	private ICountAnchorAndSalesRankListService countAnchorAndSalesRankListService;

	/**
	 * 业务员排行榜列表_优质用户榜
	 *
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/selectHighPlayerRankList.json", method = RequestMethod.POST)
	@RequiredParams(names = { "dateType", "type", "pageNo", "pageSize" })
	public BaseResponseBody<BasePage<CountAnchorAndSalesRankListVO>> selectHighPlayerRankList(HttpServletRequest request) {
		BaseResponseBody result = null;
		try {
			// 请求对象
			CountAnchorAndSalesRankListRequestVO requestVO = this.getParameterBean(CountAnchorAndSalesRankListRequestVO.class);
			SimpleDateFormat sdf = new SimpleDateFormat("MM月dd日 HH:mm");
			if (requestVO.getDateType() != null && requestVO.getType() != null) {
				// 日期逻辑
				dateWay(requestVO);
				// 分页查询
				BasePage<CountAnchorAndSalesRankListVO> page = new BasePage<CountAnchorAndSalesRankListVO>(requestVO.getPageNo(), requestVO.getPageSize());
				page = this.countAnchorAndSalesRankListService.selectHighPlayerRankListByPage(requestVO.toMap(), page);
				result = new BaseResponseBody<BasePage<CountAnchorAndSalesRankListVO>>(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.RANKING_DATA_SUCCESS.getMsg()), page);
			}
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody<BasePage<CountAnchorAndSalesRankListVO>>(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.RANKING_DATA_ERROR.getMsg()), e.getMessage(), null);
		}
		return result;
	}

	/**
	 * 业务员排行榜列表_有效注册榜
	 *
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/selectValidPlayerRankList.json", method = RequestMethod.POST)
	@RequiredParams(names = { "dateType", "type", "pageNo", "pageSize" })
	public BaseResponseBody<BasePage<CountAnchorAndSalesRankListVO>> selectValidPlayerRankList(HttpServletRequest request) {
		BaseResponseBody result = null;
		try {
			// 请求对象
			CountAnchorAndSalesRankListRequestVO requestVO = this.getParameterBean(CountAnchorAndSalesRankListRequestVO.class);
			SimpleDateFormat sdf = new SimpleDateFormat("MM月dd日 HH:mm");
			if (requestVO.getDateType() != null && requestVO.getType() != null) {
				// 日期逻辑
				dateWay(requestVO);
				// 分页查询
				BasePage<CountAnchorAndSalesRankListVO> page = new BasePage<CountAnchorAndSalesRankListVO>(requestVO.getPageNo(), requestVO.getPageSize());
				page = this.countAnchorAndSalesRankListService.selectValidPlayerRankListByPage(requestVO.toMap(), page);
				result = new BaseResponseBody<BasePage<CountAnchorAndSalesRankListVO>>(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.RANKING_DATA_SUCCESS.getMsg()), page);
			}
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody<BasePage<CountAnchorAndSalesRankListVO>>(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.RANKING_DATA_ERROR.getMsg()), e.getMessage(), null);
		}
		return result;
	}

	/**
	 * 业务员排行榜列表_三天登录榜
	 *
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/selectThirdDayLoginPlayerRankList.json", method = RequestMethod.POST)
	@RequiredParams(names = { "dateType", "type", "pageNo", "pageSize" })
	public BaseResponseBody<BasePage<CountAnchorAndSalesRankListVO>> selectThirdDayLoginPlayerRankList(HttpServletRequest request) {
		BaseResponseBody result = null;
		try {
			// 请求对象
			CountAnchorAndSalesRankListRequestVO requestVO = this.getParameterBean(CountAnchorAndSalesRankListRequestVO.class);
			SimpleDateFormat sdf = new SimpleDateFormat("MM月dd日 HH:mm");
			if (requestVO.getDateType() != null && requestVO.getType() != null) {
				// 日期逻辑
				dateWay(requestVO);
				// 分页查询
				BasePage<CountAnchorAndSalesRankListVO> page = new BasePage<CountAnchorAndSalesRankListVO>(requestVO.getPageNo(), requestVO.getPageSize());
				page = this.countAnchorAndSalesRankListService.selectThirdDayLoginPlayerRankListByPage(requestVO.toMap(), page);
				result = new BaseResponseBody<BasePage<CountAnchorAndSalesRankListVO>>(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.RANKING_DATA_SUCCESS.getMsg()), page);
			}
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody<BasePage<CountAnchorAndSalesRankListVO>>(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.RANKING_DATA_ERROR.getMsg()), e.getMessage(), null);
		}
		return result;
	}

	/**
	 * 业务员排行榜列表_七天登录榜
	 *
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/selectSeventhDayLoginPlayerRankList.json", method = RequestMethod.POST)
	@RequiredParams(names = { "dateType", "type", "pageNo", "pageSize" })
	public BaseResponseBody<BasePage<CountAnchorAndSalesRankListVO>> selectSeventhDayLoginPlayerRankList(HttpServletRequest request) {
		BaseResponseBody result = null;
		try {
			// 请求对象
			CountAnchorAndSalesRankListRequestVO requestVO = this.getParameterBean(CountAnchorAndSalesRankListRequestVO.class);
			SimpleDateFormat sdf = new SimpleDateFormat("MM月dd日 HH:mm");
			if (requestVO.getDateType() != null && requestVO.getType() != null) {
				// 日期逻辑
				dateWay(requestVO);
				// 分页查询
				BasePage<CountAnchorAndSalesRankListVO> page = new BasePage<CountAnchorAndSalesRankListVO>(requestVO.getPageNo(), requestVO.getPageSize());
				page = this.countAnchorAndSalesRankListService.selectSeventhDayLoginPlayerRankListByPage(requestVO.toMap(), page);
				result = new BaseResponseBody<BasePage<CountAnchorAndSalesRankListVO>>(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.RANKING_DATA_SUCCESS.getMsg()), page);
			}
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody<BasePage<CountAnchorAndSalesRankListVO>>(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.RANKING_DATA_ERROR.getMsg()), e.getMessage(), null);
		}
		return result;
	}

	/**
	 * 主播排行榜_业绩榜
	 *
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/selectPerformanceRankList.json", method = RequestMethod.POST)
	@RequiredParams(names = { "dateType", "type", "pageNo", "pageSize" })
	public BaseResponseBody<BasePage<CountAnchorAndSalesRankListVO>> selectPerformanceRankList(HttpServletRequest request) {
		BaseResponseBody result = null;
		try {
			// 请求对象
			CountAnchorAndSalesRankListRequestVO requestVO = this.getParameterBean(CountAnchorAndSalesRankListRequestVO.class);
			SimpleDateFormat sdf = new SimpleDateFormat("MM月dd日 HH:mm");
			if (requestVO.getDateType() != null && requestVO.getType() != null) {
				// 日期逻辑
				dateWay(requestVO);
				// 分页查询
				BasePage<CountAnchorAndSalesRankListVO> page = new BasePage<CountAnchorAndSalesRankListVO>(requestVO.getPageNo(), requestVO.getPageSize());
				page = this.countAnchorAndSalesRankListService.selectPerformanceRankListByPage(requestVO.toMap(), page);
				result = new BaseResponseBody<BasePage<CountAnchorAndSalesRankListVO>>(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.RANKING_DATA_SUCCESS.getMsg()), page);
			}
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody<BasePage<CountAnchorAndSalesRankListVO>>(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.RANKING_DATA_ERROR.getMsg()), e.getMessage(), null);
		}
		return result;
	}

	/**
	 * 业务员排行榜列表_优质用户榜和有效注册
	 *
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/selectHighPlayerAndValidRankList.json", method = RequestMethod.POST)
	@RequiredParams(names = { "pageNo", "pageSize" })
	public BaseResponseBody<BasePage<CountAnchorAndSalesRankListVO>> selectHighPlayerAndValidRankList(HttpServletRequest request) {
		BaseResponseBody result = null;
		try {
			// 请求对象
			CountAnchorAndSalesRankListRequestVO requestVO = this.getParameterBean(CountAnchorAndSalesRankListRequestVO.class);
			// 分页查询
			BasePage<CountAnchorAndSalesRankListVO> page = new BasePage<CountAnchorAndSalesRankListVO>(requestVO.getPageNo(), requestVO.getPageSize());
			page = this.countAnchorAndSalesRankListService.selectHighPlayerAndValidRankListByPage(requestVO.toMap(), page);
			result = new BaseResponseBody<BasePage<CountAnchorAndSalesRankListVO>>(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.RANKING_DATA_SUCCESS.getMsg()), page);

		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody<BasePage<CountAnchorAndSalesRankListVO>>(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.RANKING_DATA_ERROR.getMsg()), e.getMessage(), null);
		}
		return result;
	}

	/**
	 * 业务员排行榜列表_七天登录榜
	 *
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/selectLoginPlayerRankList.json", method = RequestMethod.POST)
	@RequiredParams(names = { "pageNo", "pageSize" })
	public BaseResponseBody<BasePage<CountAnchorAndSalesRankListVO>> selectLoginPlayerRankList(HttpServletRequest request) {
		BaseResponseBody result = null;
		try {
			// 请求对象
			CountAnchorAndSalesRankListRequestVO requestVO = this.getParameterBean(CountAnchorAndSalesRankListRequestVO.class);
			// 分页查询
			BasePage<CountAnchorAndSalesRankListVO> page = new BasePage<CountAnchorAndSalesRankListVO>(requestVO.getPageNo(), requestVO.getPageSize());
			page = this.countAnchorAndSalesRankListService.selectLoginPlayerRankListByPage(requestVO.toMap(), page);
			result = new BaseResponseBody<BasePage<CountAnchorAndSalesRankListVO>>(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.RANKING_DATA_SUCCESS.getMsg()), page);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody<BasePage<CountAnchorAndSalesRankListVO>>(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.RANKING_DATA_ERROR.getMsg()), e.getMessage(), null);
		}
		return result;
	}

	/**
	 * 主播排行榜_个人直播和排麦时长榜
	 *
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/selectAnchorLiveRankList.json", method = RequestMethod.POST)
	@RequiredParams(names = { "liveType", "pageNo", "pageSize" })
	public BaseResponseBody<BasePage<CountAnchorAndSalesRankListVO>> selectAnchorLiveRankList(HttpServletRequest request) {
		BaseResponseBody result = null;
		try {
			// 请求对象
			CountAnchorAndSalesRankListRequestVO requestVO = this.getParameterBean(CountAnchorAndSalesRankListRequestVO.class);
			BasePage<CountAnchorAndSalesRankListVO> page = new BasePage<CountAnchorAndSalesRankListVO>(requestVO.getPageNo(), requestVO.getPageSize());
			page = this.countAnchorAndSalesRankListService.selectAnchorLiveRankListByPage(requestVO.toMap(), page);
			result = new BaseResponseBody<BasePage<CountAnchorAndSalesRankListVO>>(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.RANKING_DATA_SUCCESS.getMsg()), page);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody<BasePage<CountAnchorAndSalesRankListVO>>(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.RANKING_DATA_ERROR.getMsg()), e.getMessage(), null);
		}
		return result;
	}

	/**
	 * 主播排行榜_业绩榜
	 *
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/selectAnchorPerformanceRankList.json", method = RequestMethod.POST)
	@RequiredParams(names = { "pageNo", "pageSize" })
	public BaseResponseBody<BasePage<CountAnchorAndSalesRankListVO>> selectAnchorPerformanceRankList(HttpServletRequest request) {
		BaseResponseBody result = null;
		try {
			// 请求对象
			CountAnchorAndSalesRankListRequestVO requestVO = this.getParameterBean(CountAnchorAndSalesRankListRequestVO.class);
			SimpleDateFormat sdf = new SimpleDateFormat("MM月dd日 HH:mm");

			// 分页查询
			BasePage<CountAnchorAndSalesRankListVO> page = new BasePage<CountAnchorAndSalesRankListVO>(requestVO.getPageNo(), requestVO.getPageSize());
			page = this.countAnchorAndSalesRankListService.selectAnchorPerformanceRankListByPage(requestVO.toMap(), page);
			result = new BaseResponseBody<BasePage<CountAnchorAndSalesRankListVO>>(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.RANKING_DATA_SUCCESS.getMsg()), page);

		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody<BasePage<CountAnchorAndSalesRankListVO>>(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.RANKING_DATA_ERROR.getMsg()), e.getMessage(), null);
		}
		return result;
	}

	/**
	 * 主播排行榜_个人直播时长榜
	 *
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/selectAnchorPersonRankList.json", method = RequestMethod.POST)
	@RequiredParams(names = { "dateType", "type", "pageNo", "pageSize" })
	public BaseResponseBody<BasePage<CountAnchorAndSalesRankListVO>> selectAnchorPersonRankList(HttpServletRequest request) {
		BaseResponseBody result = null;
		try {
			// 请求对象
			CountAnchorAndSalesRankListRequestVO requestVO = this.getParameterBean(CountAnchorAndSalesRankListRequestVO.class);
			SimpleDateFormat sdf = new SimpleDateFormat("MM月dd日 HH:mm");
			if (requestVO.getDateType() != null && requestVO.getType() != null) {
				// 日期逻辑
				dateWay(requestVO);
				// 分页查询
				requestVO.setLiveType(1);
				BasePage<CountAnchorAndSalesRankListVO> page = new BasePage<CountAnchorAndSalesRankListVO>(requestVO.getPageNo(), requestVO.getPageSize());
				// page = this.countAnchorAndSalesRankListService.selectAnchorLiveRankListByPage(requestVO.toMap(),page);
				page = this.countAnchorAndSalesRankListService.selectPersonageLiveRankListByPage(requestVO.toMap(), page);
				result = new BaseResponseBody<BasePage<CountAnchorAndSalesRankListVO>>(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.RANKING_DATA_SUCCESS.getMsg()), page);
			}
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody<BasePage<CountAnchorAndSalesRankListVO>>(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.RANKING_DATA_ERROR.getMsg()), e.getMessage(), null);
		}
		return result;
	}

	/**
	 * 主播排行榜_公会排麦直播时长榜
	 *
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/selectAnchorTradeUnionRankList.json", method = RequestMethod.POST)
	@RequiredParams(names = { "dateType", "type", "pageNo", "pageSize" })
	public BaseResponseBody<BasePage<CountAnchorAndSalesRankListVO>> selectAnchorTradeUnionRankList(HttpServletRequest request) {
		BaseResponseBody result = null;
		try {
			// 请求对象
			CountAnchorAndSalesRankListRequestVO requestVO = this.getParameterBean(CountAnchorAndSalesRankListRequestVO.class);
			SimpleDateFormat sdf = new SimpleDateFormat("MM月dd日 HH:mm");
			if (requestVO.getDateType() != null && requestVO.getType() != null) {
				// 日期逻辑
				dateWay(requestVO);
				// 分页查询
				requestVO.setLiveType(2);
				BasePage<CountAnchorAndSalesRankListVO> page = new BasePage<CountAnchorAndSalesRankListVO>(requestVO.getPageNo(), requestVO.getPageSize());
				page = this.countAnchorAndSalesRankListService.selectPersonageLiveRankListByPage(requestVO.toMap(), page);
				result = new BaseResponseBody<BasePage<CountAnchorAndSalesRankListVO>>(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.RANKING_DATA_SUCCESS.getMsg()), page);
			}
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody<BasePage<CountAnchorAndSalesRankListVO>>(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.RANKING_DATA_ERROR.getMsg()), e.getMessage(), null);
		}
		return result;
	}

	/**
	 * 业务员排行榜列表导出
	 * 
	 * @param request
	 * @param response
	 */
	@ResponseBody
	@RequestMapping(value = "/salesRankListToExcel.json")
	@SysLog(module = "统计模块", operationDesc = "榜单排行列表信息")
	public void salesRankListToExcel(HttpServletRequest request, HttpServletResponse response) {
		try {
			// 请求对象
			CountAnchorAndSalesRankListRequestVO requestVO = this.getParameterBean(CountAnchorAndSalesRankListRequestVO.class);
			// 导出榜类型 1-优质用户榜 2-有效注册榜 3-3天登录榜 4-7天登录榜
			Integer rankingType = this.getParameterInteger("rankingType", null);
			List<CountAnchorAndSalesRankListVO> list = new ArrayList<>();
			if (rankingType != null) {
				if (requestVO.getDateType() != null && requestVO.getType() != null) {
					// 日期逻辑
					dateWay(requestVO);
					if (rankingType == 1) {
						list = this.countAnchorAndSalesRankListService.selectHighPlayerRankList(requestVO.toMap());
					} else if (rankingType == 2) {
						list = this.countAnchorAndSalesRankListService.selectValidPlayerRankList(requestVO.toMap());
					} else if (rankingType == 3) {
						list = this.countAnchorAndSalesRankListService.selectThirdDayLoginPlayerRankList(requestVO.toMap());
					} else if (rankingType == 4) {
						list = this.countAnchorAndSalesRankListService.selectSeventhDayLoginPlayerRankList(requestVO.toMap());
					}
				}
			}
			// excel标题
			String[] title = { "排名", "名称", "所在军团", "优质用户数" };
			// excel文件名
			String fileName = "榜单排行列表信息" + System.currentTimeMillis() + ".xls";
			// sheet名
			String sheetName = "榜单排行列表信息";
			String[][] values = new String[list.size()][];

			if (list != null && list.size() > 0) {
				for (int i = 0; i < list.size(); i++) {
					values[i] = new String[title.length];
					CountAnchorAndSalesRankListVO obj = list.get(i);
					values[i][0] = obj.getRanking() == null ? "" : obj.getRanking().toString();
					values[i][1] = obj.getName() == null ? "" : obj.getName();
					values[i][2] = obj.getDeptName() == null ? "" : obj.getDeptName();
					values[i][3] = obj.getPlayerNum() == null ? "0" : obj.getPlayerNum().toString();
				}
			}
			outPutExcel(response, title, fileName, sheetName, values);
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage(), e);
		}
	}

	/**
	 * 主播排行榜列表导出
	 * 
	 * @param request
	 * @param response
	 */
	@ResponseBody
	@RequestMapping(value = "/anchorRankListToExcel.json")
	@SysLog(module = "统计模块", operationDesc = "榜单排行列表信息")
	public void anchorRankListToExcel(HttpServletRequest request, HttpServletResponse response) {
		try {
			// 请求对象
			CountAnchorAndSalesRankListRequestVO requestVO = this.getParameterBean(CountAnchorAndSalesRankListRequestVO.class);
			// 导出榜类型 1-个人直播时长榜 2-排麦直播时长榜 3-业绩排行榜
			Integer rankingType = this.getParameterInteger("rankingType", null);
			List<CountAnchorAndSalesRankListVO> list = new ArrayList<>();
			if (rankingType != null) {
				if (requestVO.getDateType() != null && requestVO.getType() != null) {
					// 日期逻辑
					dateWay(requestVO);
					if (rankingType == 1) {
						// 个人直播时长榜
						requestVO.setLiveType(1);
						list = this.countAnchorAndSalesRankListService.selectPersonageLiveRankList(requestVO.toMap());
					}
					if (rankingType == 2) {
						// 排麦直播时长榜
						requestVO.setLiveType(1);
						list = this.countAnchorAndSalesRankListService.selectPersonageLiveRankList(requestVO.toMap());
					}
					if (rankingType == 3) {
						// 业绩排行榜
						list = this.countAnchorAndSalesRankListService.selectPerformanceRankList(requestVO.toMap());
					}

				}
			}
			// excel标题
			String[] title = { "排名", "昵称", "所在家族", "个人直播时长" };
			List<String> titleList = Arrays.asList(title);
			if (rankingType == 2) {
				Collections.replaceAll(titleList, title[3], "排麦直播时长");
			}
			if (rankingType == 3) {
				Collections.replaceAll(titleList, title[3], "业绩");
			}
			// excel文件名
			String fileName = "榜单排行列表信息" + System.currentTimeMillis() + ".xls";
			// sheet名
			String sheetName = "榜单排行列表信息";
			String[][] values = new String[list.size()][];

			if (list != null && list.size() > 0 && rankingType == 2) {
				for (int i = 0; i < list.size(); i++) {
					values[i] = new String[title.length];
					CountAnchorAndSalesRankListVO obj = list.get(i);
					values[i][0] = obj.getRanking() == null ? "" : obj.getRanking().toString();
					values[i][1] = obj.getNickName();
					values[i][2] = obj.getFamilyName();
					values[i][3] = obj.getLiveTime();
				}
			}
			if (list != null && list.size() > 0 && rankingType == 3) {
				for (int i = 0; i < list.size(); i++) {
					values[i] = new String[title.length];
					CountAnchorAndSalesRankListVO obj = list.get(i);
					values[i][0] = obj.getRanking() == null ? "" : obj.getRanking().toString();
					values[i][1] = obj.getNickName();
					values[i][2] = obj.getFamilyName();
					values[i][3] = obj.getPerformance().toString();
				}
			}
			outPutExcel(response, title, fileName, sheetName, values);

		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage(), e);
		}

	}

	/**
	 * 输出Excel
	 *
	 * @param response
	 * @param title
	 * @param fileName
	 * @param sheetName
	 * @param values
	 * @throws IOException
	 */
	private void outPutExcel(HttpServletResponse response, String[] title, String fileName, String sheetName, String[][] values) throws IOException {
		// 创建HSSFWorkbook
		HSSFWorkbook wb = ExportExcelUtil.getHSSFWorkbook(sheetName, title, values, null);
		// 将文件存到指定位置
		this.setResponseHeader(response, fileName);
		OutputStream os = response.getOutputStream();
		wb.write(os);
		os.flush();
		os.close();
	}

	/**
	 * 发送响应流方法
	 *
	 * @param response
	 * @param fileName
	 */
	public void setResponseHeader(HttpServletResponse response, String fileName) {
		try {
			try {
				fileName = new String(fileName.getBytes(), "ISO8859-1");
			} catch (UnsupportedEncodingException e) {
				e.printStackTrace();
				logger.error(e.getMessage(), e);
			}
			response.setContentType("application/octet-stream;charset=ISO8859-1");
			response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
			response.addHeader("Pargam", "no-cache");
			response.addHeader("Cache-Control", "no-cache");
		} catch (Exception ex) {
			ex.printStackTrace();
			logger.error(ex.getMessage(), ex);
		}
	}

	/**
	 * 日期逻辑
	 * 
	 * @param requestVO
	 * @throws Exception
	 */
	public void dateWay(CountAnchorAndSalesRankListRequestVO requestVO) throws Exception {
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
		if (requestVO.getDateType() == 2) { // 周
			if (requestVO.getStartDate() == null && requestVO.getEndDate() == null) {
				requestVO.setStartDate(dateFormat.format(DataUtil.getLastWeekDateFirstDayOrBeforeLastFirstDay(new Date())));
				requestVO.setEndDate(dateFormat.format(new Date()));
			}

		} else if (requestVO.getDateType() == 3) { // 月
			if (requestVO.getStartDate() == null && requestVO.getEndDate() == null) {
				requestVO.setStartDate(dateFormat.format(DataUtil.getCurrentMonthDateBegin(new Date())));
				requestVO.setEndDate(dateFormat.format(new Date()));
			}
		} else { // 日
			if (requestVO.getStartDate() == null && requestVO.getEndDate() == null) {
				requestVO.setDateType(1);
				requestVO.setStartDate(dateFormat.format(new Date()));
				requestVO.setEndDate(dateFormat.format(new Date()));
			} else {
				requestVO.setEndDate(requestVO.getStartDate());
			}
		}
	}

}
